function Course () {
  this.name = 'fangfang'
}
Course.prototype.sayName =  function () {
  console.log(this.name)
}

function newFn (origin) {
  var obj = {}
  obj = Object.create(origin.prototype, obj)
  origin.call(obj)
  return obj
}

var course = newFn(Course)

console.log(course)
course.sayName()
// // var course = new Course()
// var isInstance =  course instanceof Course
// console.log(isInstance)

// function judgInstance (son, origin) {
//   return son.__proto__ === origin.prototype
// }

// console.log(judgInstance(course, Course))

// function fn (a, ...args) {
//   console.log(a)
//   console.log(args)
// }

// fn(1,2,3,5)
var name = 'fangfang'

Function.prototype.myCall = function (target,...args) {
  let fn = this
  var obj = target || window || global
  obj.fn = fn
  return obj.fn(...args)
}
Function.prototype.myApply = function (target, args) {
  if (!Array.isArray(args)) {
    throw new Error('参数必须为数组格式')
    return
  }
  let fn = this
  var obj = target || window || global
  obj.fn = fn
  return obj.fn(...args)

}

Function.prototype.myBind = function (target, ...outerArgs) {
  let fn = this
  return function (...innerArgs) {
    fn.apply(target,[...outerArgs,...innerArgs])
  }
}

var obj = {
  name:'jiushi'
}
function fn (...age) {
  console.log(this.name)
  console.log(age)
}

// fn.myCall(obj,1,2,3)
// fn.myApply(obj,[12,34])

const bindFn = fn.bind(obj,'q')
bindFn('a','z')

